require "import"
import "android.app.AlertDialog"
import "android.provider.DocumentsContract"

import "android.content.Intent"
import "android.net.Uri"
import "java.lang.String"
import "android.widget.*"
import "android.view.*"
import "more.request_layout"
activity.setContentView(loadlayout(request_layout))

start.onClick = function()
  uri = Uri.parse("content://com.android.externalstorage.documents/document/primary%3AAndroid%2Fdata");
  intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
  intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
  | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
  | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
  activity.startActivityForResult(intent, 6666);
end


function onActivityResult(requestCode,resultCode,data)
  activity.getContentResolver().takePersistableUriPermission(data.getData(),
  Intent.FLAG_GRANT_READ_URI_PERMISSION
  | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

  AlertDialog.Builder(activity)
  .setTitle("授权成功！")
  .setMessage("已经获得炸队目录的访问权限！")
  .setPositiveButton("关闭",{onClick=function(dialog)
    activity.finish()
  end})
  .show()
  .setCancelable(false)

end